//
//  CViewController.m
//  test
//
//  Created by admin on 2018/8/4.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CViewController.h"
#import "WYMediaReusableView.h"
#import "WYMdeiaCell.h"
@interface CViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation CViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor purpleColor];
    [self initWithPriceCollectionView];
    // Do any additional setup after loading the view.
}
-(void)initWithPriceCollectionView
{
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.itemSize=CGSizeMake(([UIScreen mainScreen].bounds.size.width-50)/4, 40);
    //横向最小距离
    layout.minimumInteritemSpacing=10.0f;
    layout.minimumLineSpacing=10.0f;
    //cell距离上  左  下 右 的距离
    layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 10);
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    [layout setHeaderReferenceSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 44)];
    
    UICollectionView *collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) collectionViewLayout:layout];
    [self.view addSubview:collection];
    collection.delegate = self;
    collection.dataSource = self;
    
    [collection registerNib:[UINib nibWithNibName:@"WYMediaReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"WYMediaReusableView"];
    
    [collection registerNib:[UINib nibWithNibName:@"WYMdeiaCell" bundle:nil] forCellWithReuseIdentifier:@"WYMdeiaCell"];
   // [collection registerNib:[UINib nibWithNibName:@"WYPriceRangeCell" bundle:nil] forCellWithReuseIdentifier:@"WYPriceRangeCell"];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 3;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
    
    
    
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WYMdeiaCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WYMdeiaCell" forIndexPath:indexPath];
    if (!cell) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"WYMdeiaCell" owner:nil options:nil].firstObject;
        }
    return cell;
}
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableview = nil;
    if (kind == UICollectionElementKindSectionHeader)
    {
        
        WYMediaReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"WYMediaReusableView" forIndexPath:indexPath];
     
        reusableview = headerView;
    }
    return reusableview;
}

@end
